
#include <atomic>
#include <glog/logging.h>
#include <stdatomic.h>
#include <thread>

std::atomic<int> g_count, x, y;
// int g_count = 0;

void t1()
{
    x.store(1, std::memory_order_seq_cst);
    LOG(INFO) << y.load(std::memory_order_seq_cst);
}

void t2()
{
    y.store(1, std::memory_order_seq_cst);
    LOG(INFO) << x.load(std::memory_order_seq_cst);
}

void work()
{
    for (int i = 0; i < 100000; ++i) {
        g_count++;
    }
}

int main(int argc, char* argv[])
{
    google::SetStderrLogging(google::LogSeverity(FLAGS_minloglevel));
    google::InitGoogleLogging(argv[0]);

    std::thread th0(work);
    std::thread th00(work);
    th0.join();
    th00.join();
    LOG(INFO) << "result: " << g_count;

    std::thread th1(t1);
    std::thread th2(t2);
    th1.join();
    th2.join();

    return 0;
}